package org.cangku.controller;

import org.cangku.dao.ShopSaleDao;
import org.cangku.entity.Shopsale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/sale")
public class ShopSaleController {
    @Autowired
    private ShopSaleDao shopSaleDao;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(int bid, int fid, String date1, String date2, int offset, int limit){
        Map<String,Object> map = new HashMap<String, Object>();
        System.out.println(fid);

        map.put("rows",shopSaleDao.query(bid,fid,date1,date2,offset,limit));
        map.put("total",shopSaleDao.getCount(bid,fid,date1,date2));

        return map;
    }

    @RequestMapping("/memberquery")
    @ResponseBody
    public Map<String,Object> memberquery(String phone, String date1, String date2, int offset, int limit){
        Map<String,Object> map = new HashMap<String, Object>();
        if(phone==null || phone.equals("")){
            map.put("rows",shopSaleDao.memberquery(phone,date1,date2,offset,limit));
            map.put("total",shopSaleDao.membercount(phone,date1,date2));
            map.put("zq","");
        }else{
            map.put("rows",shopSaleDao.memberquery(phone,date1,date2,offset,limit));
            map.put("total",shopSaleDao.membercount(phone,date1,date2));
            double zq = shopSaleDao.getZongJineByPhone(phone);
            map.put("zq",zq);
        }



        return map;
    }

}
